package com.mycompany.config;

import javax.persistence.EntityManagerFactory;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.postgresql.Driver;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import com.mycompany.dao.UserDao;
import com.mycompany.service.UserService;


@Configuration
@EnableJpaRepositories("com.mycompany.repositories")
@ComponentScan(basePackages = {"com.mycompany.ui","com.mycompany.service"})
public abstract class AppConfig {
	
	/**
	 * DataSource within of the persistence file
	 */
	
	private LocalContainerEntityManagerFactoryBean entityManagerFactory;
	


	/**
	 * Declaration of the container entityManagerFactory 
	 * @return
	 */
	
	@Bean
	public LocalContainerEntityManagerFactoryBean entityManagerFactory(){
		 entityManagerFactory = new LocalContainerEntityManagerFactoryBean();
		//entityManagerFactory.setDataSource(dataSource);
		entityManagerFactory.setPersistenceUnitName("myUnit");
		return entityManagerFactory;
	}
	
	
	@Bean
	public JpaTransactionManager transactionManager(){
		JpaTransactionManager jpaTransactionManager = new JpaTransactionManager();
		return jpaTransactionManager;
	}
	

	
//	@Bean
//	public UserDao userDao(){
//		return new UserDao();
//	}
	

	
	
}